const config = require('../src/utils/config')

const { apiPrefix } = config

let duplicateFriend = []

for (let i = 0; i < 20; i++) {
  let id = i + 1
  duplicateFriend.push({
    id: id,
    avatar: i % 10 === 0 ? 'http://wx.qlogo.cn/mmhead/ver_1/4P7EyyQ4ibNptL57TN10jZeWFV2oGfnCHOlvFia0Ejy1ycJgxdcdIa9cgwVIQYhDdvVnC816elZFW84xTqiafKvjbzVKGO9dzbN6UMKwTn1X0U/132' : '',
    count: '重复次数' + id,
    friendRemark: '重复好友备注' + id,
    friendNickname: '重复好友昵称' + id,
    customerWxId: '重复好友微号' + id
  })
}

module.exports = {
  [`GET ${apiPrefix}/duplicateFriend/query1`](req, res) {
    const { query } = req
    let { size, current, ...other } = query
    size = size || 10
    current = current || 1

    let newData = duplicateFriend
    for (let key in other) {
      if ({}.hasOwnProperty.call(other, key)) {
        newData = newData.filter((item) => {
          if ({}.hasOwnProperty.call(item, key)) {
            return String(item[key]).trim().indexOf(decodeURI(other[key]).trim()) > -1
          }
          return true
        })
      }
    }

    res.status(200).json({
      code: 0,
      message: "successed",
      data: {
        records: newData,
        total: newData.length,
      },
    })
  }
}
